<!--
 * @Description: 新增话术
 * @Author: lixianggang
 * @Date: 2022-10-17 14:25:24
 * @LastEditors: lixianggang
 * @LastEditTime: 2022-11-14 18:18:05
-->
<template>
  <div class="detail-wrap" v-loading="pageLoading">
    <div class="header-btn">
      <div>话术详情</div>
      <div>
        <el-button type="info" plain @click="goBack">返回</el-button>
      </div>
    </div>
    <div class="content">
      <div class="detail-content">
        <div class="content-item">
          <div class="item-title">分组：</div>
          <div>{{ groupName }}</div>
        </div>
        <div class="content-item">
          <div class="item-title">标题：</div>
          <div>{{ groupForm.materialName }}</div>
        </div>
        <div class="content-item">
          <div class="item-title">标题：</div>
          <el-radio-group v-model="groupForm.verbalType" disabled>
            <el-radio :label="1">文本</el-radio>
            <el-radio :label="2">图文</el-radio>
            <!-- 视频 25 M  @change="handleChange"-->
            <el-radio :label="3">视频</el-radio>
          </el-radio-group>
        </div>
        <div class="content-item">
          <div class="item-title">总发送次数：</div>
          <div>{{ sendNum }}</div>
        </div>
        <div class="content-item">
          <div class="item-title">话术内容：</div>
          <div v-if="groupForm.verbalType == 1">{{ groupForm.content }}</div>
          <img v-if="groupForm.verbalType == 2" :src="groupForm.materialUrl" class="avatar" />
          <video v-if="!groupForm.verbalType == 3" ishivideo="true" isrotate="true" autoHide="true" controls="controls"
            style="width: 280px;display: block;margin: 10px 0;" @click.stop.prevent="aaa">
            <source :src="groupForm.materialUrl" type="video/mp4">
          </video>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getGroupList, getVerbal } from '@/api/operate/verbalTrick'

export default {
  data() {
    return {
      groupForm: {
        categoryId: '',
        materialName: '',
        content: ''
      },
      id: this.$route.query.id,
      sendNum: this.$route.query.sendNum || 0,
      levelType: this.$route.query.levelType,
      pageLoading: false,
      groupName: ''
    }
  },
  methods: {
    goBack() {
      if (+this.$route.query.is_person === 99) {
        this.$router.back(-1)
      } else {
        this.$router.push({
          name: 'VerbalTrick', query: { is_person: this.$route.query.is_person }
        })
      }
    },
    handleGetGroupList() {
      return new Promise((reslove, reject) => {
        const params = {
          levelType: this.levelType,
          mediaType: 8
        }
        this.pageLoading = true
        getGroupList(params)
          .then(res => {
            this.pageLoading = false
            if (res.code === 200) {
              this.personGroupList = res.data
            }
            reslove(res)
          })
          .catch(() => {
            this.pageLoading = false
            reject()
          })
      })
    },
    handleGetVerbal() {
      return new Promise((reslove, reject) => {
        getVerbal(this.id)
          .then(res => {
            this.pageLoading = false
            if (res.code === 200) {
              this.groupForm = { ...this.groupForm, ...res.data }
            }
            reslove(res)
          })
          .catch(() => {
            this.pageLoading = false
            reject()
          })
      })
    }
  },
  mounted() {
    Promise.all([this.handleGetGroupList(), this.handleGetVerbal()])
      .then(() => {
        this.groupName = this.personGroupList.filter(item => item.id === this.groupForm.categoryId)?.[0]?.name
        console.log(this.personGroupList, this.groupForm.categoryId)
      })
  }
}
</script>

<style lang="scss" scoped>
@import "../../../styles/base.scss";

.detail-wrap {
  height: 100%;

  .header-btn {
    @include headerBtn;
  }

  .content {
    background: #fff;
    overflow: hidden;
    height: calc(100% - 60px);
    margin-top: 16px;

    .detail-content {
      width: 60%;
      margin: 20px;
      // background-color: rgba(241, 244, 246, 1);
      // border: 1px solid rgba(187, 187, 187, 1);
      padding-top: 40px;

      .content-item {
        display: flex;

        .item-title {
          width: 150px;
          text-align: right;
          margin-right: 50px;
          margin-bottom: 34px;
          flex-shrink: 0
        }
      }
    }
  }
}
</style>
